package com.prince.web.controller;

import com.prince.aspect.AppLog;
import com.prince.model.Specifications;
import com.prince.page.Page;
import com.prince.web.base.BaseController;
import com.prince.web.base.SessionUtil;
import com.prince.web.service.SpecificationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * 功能描述: 规格
 * @Author: 王培喜 58528792@163.com
 * @Date: 2021/4/6 14:24
 */
@Controller
@Validated
public class SpecificationsController extends BaseController {

    @Autowired
    private SpecificationsService specificationsService;

    /**
     * 功能描述: 分页查询规格
     * @Author: 王培喜 58528792@163.com
     * @Date: 2021/4/6 15:25
     */
    @AppLog
    @PostMapping("/findSpecificationsByPage")
    public ResponseEntity<Map<String,Object>> findSpecificationsByPage(@RequestParam Map<String,Object> params) {
        Page page = this.getRequestPageRollInfo(params);
        Map<String,Object> map = specificationsService.findSpecificationsByPage(params,page);
        return new ResponseEntity<Map<String,Object>>(map, HttpStatus.OK);
    }

    /**
     * 功能描述: 添加规格
     * @Author: 王培喜 58528792@163.com
     * @Date: 2021/4/6 16:02
     */
    @AppLog
    @PostMapping("/addSpecifications")
    public ResponseEntity<Map<String,Object>> addSpecifications(Specifications specifications) {
        specifications.setCreater(SessionUtil.getSession().getLoginName());
        Map<String,Object> map = specificationsService.addSpecifications(specifications);
        return new ResponseEntity<Map<String,Object>>(map,HttpStatus.OK);
    }
    /**
     * 功能描述: 修改规格
     * @Author: 王培喜 58528792@163.com
     * @Date: 2021/4/6 16:02
     */
    @AppLog
    @PostMapping("/updateSpecifications")
    public ResponseEntity<Map<String,Object>> updateSpecifications(Specifications specifications) {
        specifications.setUpdater(SessionUtil.getSession().getLoginName());
        Map<String,Object> map = specificationsService.updateSpecifications(specifications);
        return new ResponseEntity<Map<String,Object>>(map,HttpStatus.OK);
    }
    /**
     * 功能描述: 删除规格
     * @Author: 王培喜 58528792@163.com
     * @Date: 2021/4/6 16:02
     */
    @AppLog
    @PostMapping("/delSpecifications")
    public ResponseEntity<Map<String,Object>> delSpecifications(Specifications specifications) {
        specifications.setUpdater(SessionUtil.getSession().getLoginName());
        Map<String,Object> map = specificationsService.delSpecifications(specifications);
        return new ResponseEntity<Map<String,Object>>(map, HttpStatus.OK);
    }
    /**
     * 功能描述: 通过id查询
     * @Author: 王培喜 58528792@163.com
     * @Date: 2021/4/6 16:02
     */
    @AppLog
    @PostMapping("/findSpecificationsById")
    public ResponseEntity<Map<String,Object>> findSpecificationsById(@NotNull Integer id) {
        Map<String,Object> map = specificationsService.findSpecificationsById(id);
        return new ResponseEntity<Map<String,Object>>(map, HttpStatus.OK);
    }

    /**
     * 功能描述: 查询所有规格
     * @Author: 王培喜 58528792@163.com
     * @Date: 2021/4/6 16:02
     */
    @AppLog
    @PostMapping("/findSpecificationsAll")
    public ResponseEntity<Map<String,Object>> findSpecificationsAll() {
        Map<String,Object> map = specificationsService.findSpecificationsAll();
        return new ResponseEntity<Map<String,Object>>(map, HttpStatus.OK);
    }
}
